package com.power.sifa.correction.dao;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.correction.model.Cre_record_ga;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 公安推送记录 持久层(hibernate)
 */

public interface Cre_record_gaDao extends JpaRepository<Cre_record_ga, Serializable>, JpaSpecificationExecutor<Cre_record_ga>, Repository<Cre_record_ga, Serializable>, Cre_record_gaDaoCustom<Cre_record_ga, Serializable> {

    @Modifying
    @Transactional
    @Query("delete  from Cre_record_ga s where  s.id in (:ids) ")
    void removeByIds(@Param("ids") List<Integer> ids);

    @Query(" from Cre_record_ga s where s.perid in (:personIds) and s.rectime >= :startTime and s.rectime <= :endTime ")
    List<Cre_record_ga> findRecordByPersonIdsAndTime(@Param("personIds") List<String> personIds,
                                                     @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Query(" from Cre_record_ga s where s.taskid = :taskId ")
    List<Cre_record_ga> findRecordByTaskId(@Param("taskId") String taskId);

    @Query(" from Cre_record_ga s where s.perid = :perId order by s.rectime desc")
    List<Cre_record_ga> recentRecordGa(@Param("perId") String perId, Pageable pageable);

    @Query("select distinct g.perid from Cre_record_ga g where g.rectime >= :startTime and g.rectime <= :endTime ")
    List<String> getMonitoringPersons(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
